:root {
  --bg: #f7f8fa;
  --fg: #222;
  --muted: #666;
  --card: #fff;
  --primary: #2563eb;
  --primary-fg: #fff;
  --danger: #dc2626;
  --success: #16a34a;
  --border: #e5e7eb;
  --accent: #94a3b8;
  --warn: #f97316;
  --due: #fee2e2;
  --due-border: #fecaca;
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --fg: #e5e7eb;
  --muted: #94a3b8;
  --card: #111827;
  --primary: #60a5fa;
  --primary-fg: #0b1020;
  --danger: #f87171;
  --success: #34d399;
  --border: #1f2937;
  --accent: #6b7280;
  --warn: #fb923c;
  --due: #2b1a1a;
  --due-border: #6b1d1d;
}

html[data-theme="solar"] {
  --bg: #fff8f0;
  --fg: #2b2b2b;
  --muted: #8c6d62;
  --card: #fffaf5;
  --primary: #ff7e33;
  --primary-fg: #2b2b2b;
  --danger: #e63946;
  --success: #2a9d8f;
  --border: #f0dfcd;
  --accent: #e9c46a;
  --warn: #f4a261;
  --due: #ffe2dc;
  --due-border: #ffc2b5;
}

html[data-theme="contrast"] {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #333;
  --card: #ffffff;
  --primary: #000000;
  --primary-fg: #ffffff;
  --danger: #000000;
  --success: #000000;
  --border: #000000;
  --accent: #000000;
  --warn: #000000;
  --due: #ffeded;
  --due-border: #ff0000;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft Yahei", "Noto Sans", sans-serif; height: 100%; }

.app-header {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--card);
  position: sticky; top: 0; z-index: 10;
}
.app-header .left, .app-header .right { display: flex; gap: 8px; align-items: center; }
.app-header .center { text-align: center; }
.app-title { font-weight: 700; letter-spacing: 0.5px; }

.btn { border: 1px solid var(--border); background: var(--card); color: var(--fg); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.success { border-color: var(--success); color: var(--success); }
.btn.small { padding: 2px 6px; font-size: 12px; border-radius: 4px; }

.select, input[type="text"], input[type="url"], input[type="number"], input[type="datetime-local"], textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--fg);
}

.app-main { display: grid; grid-template-columns: 320px 1fr; gap: 12px; padding: 12px; height: calc(100vh - 56px); }
.sidebar { display: flex; flex-direction: column; gap: 12px; overflow: auto; }

.panel { border: 1px solid var(--border); background: var(--card); border-radius: 10px; display: flex; flex-direction: column; min-height: 160px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.panel-body { padding: 8px; overflow: auto; }
.panel-footer { padding: 6px 10px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.tip { font-style: italic; }

.matrix { overflow: hidden; }
.matrix-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 12px; height: 100%; }
.cell { border: 1px solid var(--border); border-radius: 10px; background: var(--card); display: flex; flex-direction: column; }
.cell-header { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.cell-body { padding: 8px; overflow: auto; display: flex; flex-direction: column; gap: 8px; min-height: 100px; }

.task-card, .idea-card { border: 1px solid var(--border); background: var(--card); border-radius: 10px; }
.task-card.due-soon { background: var(--due); border-color: var(--due-border); }
.task-card.dragging { opacity: 0.6; box-shadow: 0 0 8px var(--primary); }
.task-header, .idea-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: move; }
.task-header .title { font-weight: 600; }
.task-body, .idea-body { padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.meta-item em { font-style: normal; color: var(--fg); }
.progress-row { gap: 8px; }
.progress-row .progress-label { width: 48px; color: var(--muted); }
.progress-row .progress-text { min-width: 40px; text-align: right; }
.progress-range { flex: 1; cursor: ew-resize; }

.memo summary { cursor: pointer; color: var(--muted); }
.memo-content { white-space: pre-wrap; color: var(--fg); }

.idea-card .content { font-weight: 600; }
.idea-card .time { font-size: 12px; color: var(--muted); }

.trash-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--card); display: flex; flex-direction: column; gap: 6px; }
.trash-item .head { display: flex; justify-content: space-between; align-items: center; }
.trash-item .label { font-weight: 600; }
.trash-item .info { color: var(--muted); font-size: 12px; }

.modal { border: none; padding: 0; border-radius: 10px; width: min(720px, 92vw); }
.modal::backdrop { background: rgba(0,0,0,0.3); }
.modal-form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-form .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.drag-over { outline: 2px dashed var(--primary); outline-offset: 2px; border-radius: 10px; }

.minimap {
  position: fixed; right: 12px; bottom: 12px; width: 240px; border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,0.1); user-select: none; z-index: 20;
}
.minimap[data-locked="true"] { cursor: default; }
.minimap[data-locked="false"] { cursor: move; }
.minimap-header { padding: 8px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.mini-legend { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot-q1 { background: #ef4444; }
.dot-q2 { background: #10b981; }
.dot-q3 { background: #f59e0b; }
.dot-q4 { background: #3b82f6; }
.minimap-body { padding: 8px; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini-cell { border: 1px dashed var(--border); border-radius: 6px; height: 60px; position: relative; }
.mini-stats { position: absolute; inset: 2px; font-size: 11px; color: var(--muted); padding: 2px; }
.mini-stats .count { font-weight: 700; color: var(--fg); }

@media (max-width: 1100px) {
  .app-main { grid-template-columns: 1fr; }
  .sidebar { order: 2; }
  .matrix { order: 1; }
}

@media (max-width: 720px) {
  .matrix-grid { grid-template-columns: 1fr; grid-template-rows: auto; }
  .cell { min-height: 220px; }
  .app-header { grid-template-columns: 1fr; gap: 8px; }
  .app-header .left, .app-header .right { flex-wrap: wrap; }
  .modal-form .grid-2 { grid-template-columns: 1fr; }
}

.drag-handle { cursor: grab; }
.progress-range::-webkit-slider-thumb { cursor: ns-resize; }
